package cs235.avl;


public abstract class BinaryTree<T extends Comparable<T>> implements Tree<T>{

    protected class Node implements BinaryTreeNode {

        private T value;
        private Node left;
        private Node right;
        private int height;

        public Node(T item) {
            this(item, null, null);
        }

        public Node(T item, Node left, Node right) {
            this.value = item;
            this.left = left;
            this.right = right;
        }

        @Override
        public Object getData() {
            return value;
        }

        @Override
        public BinaryTreeNode getLeftChild() {
            return left;
        }
        

        @Override
        public BinaryTreeNode getRightChild() {
            return right;
        }
        

        @Override
        public int getHeight() {
            return height;
        }
    }

    private Node root;


    public T findMin() {
        return findMin(root);
    }

    private T findMin(Node t) {
        if (t != null) {
            while (t.left != null){
                t = t.left;
            }
            return t.value;
        }
        return null;
    }

    public T findMax() {
        return findMax(root);
    }

    private T findMax(Node t) {
        if (t != null) {
            while (t.right != null)
                t = t.right;
            return t.value;
        }
        return null;
    }

}
